package com.ruoyi.wms.service;

import com.ruoyi.common.core.utils.MapstructUtils;
import com.ruoyi.common.mybatis.core.page.TableDataInfo;
import com.ruoyi.common.mybatis.core.page.PageQuery;
import com.ruoyi.common.core.utils.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.ruoyi.wms.domain.bo.MailboxInstructionsBo;
import com.ruoyi.wms.domain.vo.MailboxInstructionsVo;
import com.ruoyi.wms.domain.entity.MailboxInstructions;
import com.ruoyi.wms.mapper.MailboxInstructionsMapper;

import java.util.List;
import java.util.Map;
import java.util.Collection;

/**
 * 来信须知Service业务层处理
 *
 * @author zcc
 * @date 2024-12-14
 */
@RequiredArgsConstructor
@Service
public class MailboxInstructionsService {

    private final MailboxInstructionsMapper mailboxInstructionsMapper;

    /**
     * 查询来信须知
     */
    public MailboxInstructionsVo queryById(Long id){
        return mailboxInstructionsMapper.selectVoById(id);
    }

    /**
     * 查询来信须知列表
     */
    public TableDataInfo<MailboxInstructionsVo> queryPageList(MailboxInstructionsBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<MailboxInstructions> lqw = buildQueryWrapper(bo);
        Page<MailboxInstructionsVo> result = mailboxInstructionsMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    /**
     * 查询来信须知列表
     */
    public List<MailboxInstructionsVo> queryList(MailboxInstructionsBo bo) {
        LambdaQueryWrapper<MailboxInstructions> lqw = buildQueryWrapper(bo);
        return mailboxInstructionsMapper.selectVoList(lqw);
    }

    private LambdaQueryWrapper<MailboxInstructions> buildQueryWrapper(MailboxInstructionsBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<MailboxInstructions> lqw = Wrappers.lambdaQuery();
        lqw.like(StringUtils.isNotBlank(bo.getName()), MailboxInstructions::getName, bo.getName());
        lqw.eq(StringUtils.isNotBlank(bo.getContent()), MailboxInstructions::getContent, bo.getContent());
        return lqw;
    }

    /**
     * 新增来信须知
     */
    public void insertByBo(MailboxInstructionsBo bo) {
        MailboxInstructions add = MapstructUtils.convert(bo, MailboxInstructions.class);
        mailboxInstructionsMapper.insert(add);
    }

    /**
     * 修改来信须知
     */
    public void updateByBo(MailboxInstructionsBo bo) {
        MailboxInstructions update = MapstructUtils.convert(bo, MailboxInstructions.class);
        mailboxInstructionsMapper.updateById(update);
    }

    /**
     * 批量删除来信须知
     */
    public void deleteByIds(Collection<Long> ids) {
        mailboxInstructionsMapper.deleteBatchIds(ids);
    }
}
